package model

import (
	"database/sql"
	"time"

	"github.com/guregu/null"
	"github.com/satori/go.uuid"
)

var (
	_ = time.Second
	_ = sql.LevelDefault
	_ = null.Bool{}
	_ = uuid.UUID{}
)

/*
DB Table Details
-------------------------------------


CREATE TABLE "invoices"
(
    [InvoiceId] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    [CustomerId] INTEGER  NOT NULL,
    [InvoiceDate] DATETIME  NOT NULL,
    [BillingAddress] NVARCHAR(70),
    [BillingCity] NVARCHAR(40),
    [BillingState] NVARCHAR(40),
    [BillingCountry] NVARCHAR(40),
    [BillingPostalCode] NVARCHAR(10),
    [Total] NUMERIC(10,2)  NOT NULL,
    FOREIGN KEY ([CustomerId]) REFERENCES "customers" ([CustomerId])
		ON DELETE NO ACTION ON UPDATE NO ACTION
)

JSON Sample
-------------------------------------
{    "invoice_id": 1,    "customer_id": 13,    "billing_city": "kemJNuAeBldBKgLpcdIDApMZA",    "billing_state": "jKlWGCRhEZnKtlscUjADjahdT",    "invoice_date": "2180-09-27T17:26:36.982509468+08:00",    "billing_address": "dcVmqOpTbQIqyDidtuZmDehxR",    "billing_country": "jhaPViPvIvFFmRVncrKveEqYk",    "billing_postal_code": "kbpXPFReVCHnDLHITPHUNNJxR",    "total": 0.21108554500818064}



*/

// Invoices struct is a row record of the invoices table in the main database
type Invoices struct {
	//[ 0] InvoiceId                                      integer              null: false  primary: true   isArray: false  auto: true   col: integer         len: -1      default: []
	InvoiceID int32 `gorm:"primary_key;AUTO_INCREMENT;column:InvoiceId;type:integer;" json:"invoice_id"`
	//[ 1] CustomerId                                     integer              null: false  primary: false  isArray: false  auto: false  col: integer         len: -1      default: []
	CustomerID int32 `gorm:"column:CustomerId;type:integer;" json:"customer_id"`
	//[ 2] InvoiceDate                                    datetime             null: false  primary: false  isArray: false  auto: false  col: datetime        len: -1      default: []
	InvoiceDate time.Time `gorm:"column:InvoiceDate;type:datetime;" json:"invoice_date"`
	//[ 3] BillingAddress                                 nvarchar(70)         null: true   primary: false  isArray: false  auto: false  col: nvarchar        len: 70      default: []
	BillingAddress null.String `gorm:"column:BillingAddress;type:nvarchar;size:70;" json:"billing_address"`
	//[ 4] BillingCity                                    nvarchar(40)         null: true   primary: false  isArray: false  auto: false  col: nvarchar        len: 40      default: []
	BillingCity null.String `gorm:"column:BillingCity;type:nvarchar;size:40;" json:"billing_city"`
	//[ 5] BillingState                                   nvarchar(40)         null: true   primary: false  isArray: false  auto: false  col: nvarchar        len: 40      default: []
	BillingState null.String `gorm:"column:BillingState;type:nvarchar;size:40;" json:"billing_state"`
	//[ 6] BillingCountry                                 nvarchar(40)         null: true   primary: false  isArray: false  auto: false  col: nvarchar        len: 40      default: []
	BillingCountry null.String `gorm:"column:BillingCountry;type:nvarchar;size:40;" json:"billing_country"`
	//[ 7] BillingPostalCode                              nvarchar(10)         null: true   primary: false  isArray: false  auto: false  col: nvarchar        len: 10      default: []
	BillingPostalCode null.String `gorm:"column:BillingPostalCode;type:nvarchar;size:10;" json:"billing_postal_code"`
	//[ 8] Total                                          numeric              null: false  primary: false  isArray: false  auto: false  col: numeric         len: -1      default: []
	Total float64 `gorm:"column:Total;type:numeric;" json:"total"`
}

var invoicesTableInfo = &TableInfo{
	Name: "invoices",
	Columns: []*ColumnInfo{

		&ColumnInfo{
			Index:              0,
			Name:               "InvoiceId",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       true,
			IsAutoIncrement:    true,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "InvoiceID",
			GoFieldType:        "int32",
			JSONFieldName:      "invoice_id",
			ProtobufFieldName:  "invoice_id",
			ProtobufType:       "int32",
			ProtobufPos:        1,
		},

		&ColumnInfo{
			Index:              1,
			Name:               "CustomerId",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "integer",
			DatabaseTypePretty: "integer",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "integer",
			ColumnLength:       -1,
			GoFieldName:        "CustomerID",
			GoFieldType:        "int32",
			JSONFieldName:      "customer_id",
			ProtobufFieldName:  "customer_id",
			ProtobufType:       "int32",
			ProtobufPos:        2,
		},

		&ColumnInfo{
			Index:              2,
			Name:               "InvoiceDate",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "datetime",
			DatabaseTypePretty: "datetime",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "datetime",
			ColumnLength:       -1,
			GoFieldName:        "InvoiceDate",
			GoFieldType:        "time.Time",
			JSONFieldName:      "invoice_date",
			ProtobufFieldName:  "invoice_date",
			ProtobufType:       "google.protobuf.Timestamp",
			ProtobufPos:        3,
		},

		&ColumnInfo{
			Index:              3,
			Name:               "BillingAddress",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(70)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       70,
			GoFieldName:        "BillingAddress",
			GoFieldType:        "null.String",
			JSONFieldName:      "billing_address",
			ProtobufFieldName:  "billing_address",
			ProtobufType:       "string",
			ProtobufPos:        4,
		},

		&ColumnInfo{
			Index:              4,
			Name:               "BillingCity",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(40)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       40,
			GoFieldName:        "BillingCity",
			GoFieldType:        "null.String",
			JSONFieldName:      "billing_city",
			ProtobufFieldName:  "billing_city",
			ProtobufType:       "string",
			ProtobufPos:        5,
		},

		&ColumnInfo{
			Index:              5,
			Name:               "BillingState",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(40)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       40,
			GoFieldName:        "BillingState",
			GoFieldType:        "null.String",
			JSONFieldName:      "billing_state",
			ProtobufFieldName:  "billing_state",
			ProtobufType:       "string",
			ProtobufPos:        6,
		},

		&ColumnInfo{
			Index:              6,
			Name:               "BillingCountry",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(40)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       40,
			GoFieldName:        "BillingCountry",
			GoFieldType:        "null.String",
			JSONFieldName:      "billing_country",
			ProtobufFieldName:  "billing_country",
			ProtobufType:       "string",
			ProtobufPos:        7,
		},

		&ColumnInfo{
			Index:              7,
			Name:               "BillingPostalCode",
			Comment:            ``,
			Notes:              ``,
			Nullable:           true,
			DatabaseTypeName:   "nvarchar",
			DatabaseTypePretty: "nvarchar(10)",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "nvarchar",
			ColumnLength:       10,
			GoFieldName:        "BillingPostalCode",
			GoFieldType:        "null.String",
			JSONFieldName:      "billing_postal_code",
			ProtobufFieldName:  "billing_postal_code",
			ProtobufType:       "string",
			ProtobufPos:        8,
		},

		&ColumnInfo{
			Index:              8,
			Name:               "Total",
			Comment:            ``,
			Notes:              ``,
			Nullable:           false,
			DatabaseTypeName:   "numeric",
			DatabaseTypePretty: "numeric",
			IsPrimaryKey:       false,
			IsAutoIncrement:    false,
			IsArray:            false,
			ColumnType:         "numeric",
			ColumnLength:       -1,
			GoFieldName:        "Total",
			GoFieldType:        "float64",
			JSONFieldName:      "total",
			ProtobufFieldName:  "total",
			ProtobufType:       "float",
			ProtobufPos:        9,
		},
	},
}

// TableName sets the insert table name for this struct type
func (i *Invoices) TableName() string {
	return "invoices"
}

// BeforeSave invoked before saving, return an error if field is not populated.
func (i *Invoices) BeforeSave() error {
	return nil
}

// Prepare invoked before saving, can be used to populate fields etc.
func (i *Invoices) Prepare() {
}

// Validate invoked before performing action, return an error if field is not populated.
func (i *Invoices) Validate(action Action) error {
	return nil
}

// TableInfo return table meta data
func (i *Invoices) TableInfo() *TableInfo {
	return invoicesTableInfo
}
